<?php
class Chuyenmuc_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
    }
    //Xóa chuyen muc
    function xoa($id)
    {
        $this->db->where('id_chuyenmuc',$id);
        $result = $this->db->delete('chuyenmuc');
        return $result;
    }
    //Sửa chuyên mục
    function suachuyenmuc($id,$tenchuyenmuc,$loaichuyenmuc,$ngonngu,$id_mark,$id_nguoisua,$ten_nguoisua,$ngaysua)
    {
        if(!isset($id)||!isset($tenchuyenmuc)||!isset($loaichuyenmuc)||!isset($ngonngu)||!isset($id_mark)) return false;
        $data =array(
	        'ten_chuyenmuc'=>$tenchuyenmuc,
	        'loaichuyenmuc'=>$loaichuyenmuc,
	        'ngonngu'=>$ngonngu,
	        'id_mark'=>$id_mark,
        	'id_nguoisua'=>$id_nguoisua,
	        'ten_nguoisua'=>$ten_nguoisua,
        	'ngaysua'=>$ngaysua
        );
        $this->db->where('id_chuyenmuc',$id);
        $result=$this->db->update('chuyenmuc',$data);
        return $result;         
    }
    //Tạo chuyên mục
    function taochuyenmuc($tenchuyenmuc,$loaichuyenmuc,$ngonngu,$id_mark,$id_nguoitao,$ten_nguoitao)
    {
        if(!isset($tenchuyenmuc)||!isset($loaichuyenmuc)||!isset($ngonngu)||!isset($id_mark)||!isset($id_nguoitao)||!isset($ten_nguoitao)) return false;
        $data =array(
	        'ten_chuyenmuc'=>$tenchuyenmuc,
	        'loaichuyenmuc'=>$loaichuyenmuc,
	        'ngonngu'=>$ngonngu,
	        'id_mark'=>$id_mark,
	        'id_nguoitao'=>$id_nguoitao,
	        'ten_nguoitao'=>$ten_nguoitao
        );
        $result=$this->db->insert('chuyenmuc',$data);
        return $result;
    }

    function xemchuyenmuc($id){
    	$this->db->where('id_chuyenmuc',$id);
        $query = $this->db->get('chuyenmuc');
        if($query -> num_rows() != 0) return $query->result_array();
		else return false;	
    }
    function laytenchuyenmuc($id)
    {
        $this->db->select('ten_chuyenmuc');
        $this->db->where('id_chuyenmuc',$id);
        $query=$this->db->get('chuyenmuc');
        if($query->num_rows()!=0) 
        {
            $result=$query->result_array();
            foreach($result as $row);
            return $row['ten_chuyenmuc'];
        }
        return false;
    }   
    //Lấy chuyên mục theo ngôn ngữ
    function laychuyenmuc($ngonngu)
    {
        $this->db->where('ngonngu',$ngonngu);
        $result=$this->db->get('chuyenmuc');
        return $result->result_array();
    }
    //Lấy chuyên mục theo id ngôn ngữ
    function laychuyenmucID($ngonngu)
    {
        $this->db->where('ngonngu',$ngonngu);
        $result=$this->db->get('chuyenmuc');
        return $result->result_array();
    }
}
?>